package com.aaa.tars.controller;

import com.aaa.tars.entity.Scenic;
import com.aaa.tars.entity.ScenicPic;
import com.aaa.tars.service.ScenicPicService;
import com.aaa.tars.service.ScenicService;
import com.aaa.tars.util.OssUtil;
import com.aaa.tars.util.Page;
import com.aaa.tars.util.Result;
import com.aaa.tars.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @FileName: ScenicPicController
 * @Description:
 * @Author: 李宗盛
 * @CreateTime: 2025/9/9 10:49
 * @Version: 17
 */
@RestController
@RequestMapping("scenicPic")
public class ScenicPicController {
    @Autowired
    private ScenicPicService scenicPicService;
    @PostMapping("queryByPage")
    public Result queryByPage(@RequestBody Page<ScenicPic> page){
        return ResultUtil.success(scenicPicService.queryByPage(page));
    }
    @GetMapping("queryById")
    public Result queryById( Integer dotId){
        return ResultUtil.success(scenicPicService.queryById(dotId));
    }
    @PostMapping("add")
    public  Result add(@RequestBody ScenicPic scenicPic){
        // 设置创建时间为当前时间
        scenicPic.setSctime(new Date());
        return  ResultUtil.success(scenicPicService.add(scenicPic));
    }
    @PutMapping("update")
    public  Result update(@RequestBody ScenicPic scenicPic){
        return  ResultUtil.success(scenicPicService.update(scenicPic));
    }
    @DeleteMapping("deleteById")
    public  Result deleteById(Integer dotId){
        return  ResultUtil.success(scenicPicService.deleteById(dotId));
    }
    /**
     * 上传图片
     * @param file
     * @return
     */
    @PostMapping("/uploadImage")
    public Result uploadImage(@RequestParam("file") MultipartFile file) {
        return scenicPicService.uploadImage(file);
    }
}
